<header class="newsheader">Administration</header>
<section class="newssection">

		<form method="post" action="">
            <input type="submit" name="reg" value="Create new user" />
        </form>
        <form method="post" action="">
            <input type="submit" name="news" value="Create new post" />
        </form>
        <form method="post" action="">
            <p>search for a user: <input name="edit" size="13" /></p>
            <input type="submit" value="Search" />
        </form>
        <?
        if(isset($_POST['edit'])) {
			$row = getUser($_POST['edit']);
			echo '<form method="post" action="">
					<p><input type="hidden" name="userid" size="13" value="' . $row['userid'] . '" /></p>
            		<p>Edit username: <input name="username" size="13" value="' . $row['username'] . '" /></p>
					<p>Edit email: <input name="email" size="13" value="' . $row['email'] . '" /></p>
					<p>Edit adminrights: <input name="admin" size="13" value="' . $row['admin'] . '" /></p>
            		<input type="submit" name="save" value="Save changes" />
       			 </form>
       			 <form method="post" action="">
					<input type="submit" name="delete" value="Remove user" />
       			 </form>';
			if(isset($_POST['userid'])) {
				updateUser($_POST['userid'], $_POST['username'], $_POST['email'], $_POST['admin']);	
				echo 'Update successful!';
			}
			
			if(isset($_POST['delete'])) {
				$row = getUser($_POST['edit']);
				removeUser($row['userid']);
			}
			
			
		}
		if(isset($_POST['reg'])) {
			echo '<form method="post" action="">
					<input type="hidden" name="reg" size="13" value="1" />
            		<p>Edit username: <input name="username" size="13" /></p>
					<p>Edit email: <input name="email" size="13"/></p>
					<p>Edit adminrights: <input name="admin" size="13" /></p>
					<p>Edit password: <input name="password" size="13" /></p>
					<p>Edit repeat password: <input name="repeat" size="13" /></p>
            		<input type="submit" name="create" value="Create user" />
       			 </form>';
			if(isset($_POST['create'])) {
				if($_POST['password'] == $_POST['repeat']) {
					$fisk = registerUser($_POST['username'], $_POST['email'], $_POST['password'], $_POST['admin']);
				} else {
					echo 'Passwords do not match.';
				}
			}		
		}
		
		if(isset($_POST['news'])) {
			echo '<form method="post" action="">
					<input type="hidden" name="topic" size="13" value="1"/>
            		<p>Topic: <input name="topic" size="13" /></p>
					<p>text<TEXTAREA NAME="news" COLS=40 ROWS=6></TEXTAREA></p>
            		<input type="submit" name="postNews" value="Create post" />
       			 </form>';
			if(isset($_POST['postNews'])) {
				echo $_POST['news'];
				echo $_POST['topic'];
				echo $_SESSION['username'];
				writeNews($_POST['news'], $_SESSION['username'], $_POST['topic']);
			}		
		}
		?>
</section>
<footer class="newsfooter"></footer>